//
//  VcOfWebView.m
//  ProjectA_ManualGuest
//
//  Created by dingcong on 16/6/23.
//  Copyright © 2016年 丁聪. All rights reserved.
//

#import "VcOfWebView.h"
#import "PrefixHeader.pch"
#import "UMSocialData.h"
#import "UMSocial.h"
#import "UMSocialSnsService.h"
#import "DBHandler.h"
#import "SelectionModel.h"
#import <WebKit/WebKit.h>
@interface VcOfWebView ()<UMSocialUIDelegate>

@property(nonatomic, retain)WKWebView *wk;


@end

@implementation VcOfWebView



- (void)dealloc{
    
    [_buttonOfCollection release];
    [_buttonOfShare release];
    [_wk release];
    [_strOfId release];
    [super dealloc];
    
    
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    

    
    
    [self.navigationItem setTitle:@"专题详情"];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
   

    self.wk = [[WKWebView alloc]init];
    [self.wk loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:self.strOfId]]];
    self.wk.frame = self.view.frame;
    [self.view addSubview:self.wk];
    self.buttonOfShare = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonOfShare.frame = CGRectMake(CGRectGetWidth(self.view.bounds) - 30, 0, 0, 0);
    
    
    self.buttonOfCollection = [UIButton buttonWithType:UIButtonTypeCustom];
    self.buttonOfCollection.frame = CGRectMake(SCREEN_WIDTH, 0, 0, 0);
    
    
    [self.view addSubview:self.buttonOfShare];
    [self.view addSubview:self.buttonOfCollection];
  self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(handleShare:)];
    [self.wk release];

}

- (void)handleShare:(UIBarButtonItem *)share
{
    if (self.buttonOfShare.frame.size.height == 0)
    {
        [UIView animateWithDuration:0.5 animations:^{
            
            self.buttonOfShare.frame = CGRectMake(SCREEN_WIDTH - SCREEN_WIDTH / 4.5, 64, 32, 32);
            self.buttonOfShare.layer.cornerRadius =  18;
            self.buttonOfCollection.frame = CGRectMake((SCREEN_WIDTH - SCREEN_WIDTH / 4.5) + 45, 64, 32, 32);
            self.buttonOfShare.tintColor = [UIColor redColor];
            [self.buttonOfShare addTarget:self action:@selector(Share:) forControlEvents:UIControlEventTouchUpInside];
            
            
            [self.buttonOfShare setImage:[UIImage imageNamed:@"fenxiang.png"] forState:UIControlStateNormal];
            [self.buttonOfCollection setTintColor:[UIColor redColor]];
            [self.buttonOfShare setTintColor:[UIColor redColor]];
            self.buttonOfCollection.layer.cornerRadius = 18;
            [self.buttonOfCollection setImage:[UIImage imageNamed:@"shoucang.png"] forState:UIControlStateNormal];
            [self.buttonOfCollection addTarget:self action:@selector(collection:) forControlEvents:UIControlEventTouchUpInside];
        }];
    }
    else{
        
        [UIView animateWithDuration:0.5 animations:^{
           
            self.buttonOfShare.frame = CGRectMake(CGRectGetWidth(self.view.bounds) - 30, 50, 0, 0);
            self.buttonOfCollection.frame = CGRectMake((SCREEN_WIDTH - 30), 50, 0, 0);
        }];
        
        
    }
    
}

- (void)Share:(UIButton *)share{
        [UMSocialData defaultData].extConfig.wechatTimelineData.title = @"微信朋友圈title";
        [UMSocialData defaultData].extConfig.wechatSessionData.title = @"微信好友title";
        [UMSocialData defaultData].extConfig.wechatTimelineData.url = @"http://baidu.com";
        [UMSocialData defaultData].extConfig.wechatSessionData.url = @"http://baidu.com";
        [UMSocialData defaultData].extConfig.title = @"分享的title";
        [UMSocialData defaultData].extConfig.qqData.url = @"http://baidu.com";
        [UMSocialSnsService presentSnsIconSheetView:self
                                             appKey:@"57709afd67e58ea3950004ef"
                                          shareText:[NSString stringWithFormat:@"%@, %@", self.strOfname, self.strOfId]
                                         shareImage:[UIImage imageNamed:@"icon"]
                                    shareToSnsNames:@[UMShareToWechatSession,UMShareToWechatTimeline,UMShareToSina,UMShareToQQ,UMShareToQzone]
                                           delegate:self];

    
    
    
    
    
}

- (void)collection:(UIButton *)collection
{
    [[DBHandler sharedDBHandle]openDB];
    
   
    [[DBHandler sharedDBHandle]createTable];
    
    
    
    [[DBHandler sharedDBHandle]insertModel:_model];
                 
                     
    [[DBHandler sharedDBHandle]searchForName:_model.subject];
    
    
    
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
